import { Agenda } from "../../dto/agenda";

export function agendaProcess(items: any[]){
   const result: Agenda[]=[];
   
   for(let i=0;i<items.length;i++){
      const item=items[i];
      const agenda: Agenda={
          id: item.id,
          name: item.name,
          description: item.description,
          startTime: formatTime(item.startTime),
          endTime: formatTime(item.startTime),
          isImportant: item.isImportant,
          timeDetail: item.timeDetail
      }
      result.push(agenda);
   }
   return result;
}
//时间戳转换为年月日时分秒
export function formatTime(time:number){
   //将时间戳格式转换成年月日时分秒
   var date = new Date(time);
   var Y = date.getFullYear() + '-';
   var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
   var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';

   var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
   var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
   var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
   var strDate = Y + M + D + h + m + s;
   return strDate;
}